Socket
Socket
Sign inDemoInstall

oas-validator

Package Overview
Dependencies
33
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    oas-validator

Parser/validator for OpenAPI 3.x definitions


Version published
Weekly downloads
1.2M
decreased by-16.06%
Maintainers
1
Install size
2.04 MB
Created
Weekly downloads
 

Package description

What is oas-validator?

The oas-validator npm package is used to validate OpenAPI Specification (OAS) documents. It ensures that the OAS documents adhere to the OpenAPI standards and helps in identifying any discrepancies or errors in the API definitions.

What are oas-validator's main functionalities?

Validate OpenAPI 3.0 documents

This feature allows you to validate OpenAPI 3.0 documents to ensure they conform to the OpenAPI Specification. The code sample reads an OpenAPI document from a file and validates it using the oas-validator package.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/openapi.json', 'utf8'));

validator.validate(apiSpec, {}, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Validate OpenAPI 2.0 (Swagger) documents

This feature allows you to validate OpenAPI 2.0 (Swagger) documents. The code sample reads a Swagger document from a file and validates it using the oas-validator package, specifying the version as '2.0'.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/swagger.json', 'utf8'));

validator.validate(apiSpec, { version: '2.0' }, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Custom validation options

This feature allows you to use custom validation options such as linting and schema validation. The code sample demonstrates how to pass custom options to the validator.

const validator = require('oas-validator');
const fs = require('fs');

const apiSpec = JSON.parse(fs.readFileSync('path/to/openapi.json', 'utf8'));

const options = {
  lint: true,
  validateSchema: true
};

validator.validate(apiSpec, options, (err, options) => {
  if (err) {
    console.error('Validation failed:', err);
  } else {
    console.log('Validation succeeded');
  }
});

Other packages similar to oas-validator

Readme

Source

oas-validator

Usage:

const validator = require('oas-validator');
const options = {};
validator.validate(openapi, options)
.then(function(options){
  // options.valid contains the result of the validation, true in this branch
})
.catch(function(err){
  console.warn(err.message);
  if (options.context) console.warn('Location',options.context.pop());
});

If a third callback argument to validate is provided, the callback will be called instead of a Promise being returned.

oas-validator is an assertion-based validator, which stops on the first error, as structural errors may otherwise cause further (spurious) errors to be reported. If the lint option is set, multiple warnings may be reported.

See here for complete documentation of the options object.

Keywords

FAQs

Last updated on 07 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc